import { defineStore } from 'pinia';
// import instance from '@/utils/request';
import { http } from '../../utils/request';
import type { CategoryList } from '@/types';

const useHomeStore = defineStore('home', {
  // state对应vue2data
  state: () => {
    return {
      categoryList: [] as CategoryList,
    };
  },
  //  state 对应 vue2 的 computed
  getters: {},

  //  state 对应 vue2 的 methods
  actions: {
    async getAllCategory() {
      // const res = await instance.get('/home/category/head');
      // const res = await instance.get<Res<CategoryList>>('/home/category/head');
      const res = await http<CategoryList>('GET', '/home/category/head');
      console.log('res: ', res);
      this.categoryList = res.data.result;
    },
  },
});
export default useHomeStore;
